from typing import Optional
from pydantic_settings import BaseSettings

# 应用设置类
class Settings(BaseSettings):
    # 数据库配置
    # 确保使用pymysql驱动
    database_url: str = "mysql+pymysql://root:lh540308@localhost:3306/fastapi_auth"
    
    # Redis配置
    redis_url: str = "redis://lh540308@localhost:6379/0"
    
    # JWT配置
    secret_key: str = "your-secret-key-here"
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 30
    
    # 应用配置
    app_name: str = "FastAPI认证系统"
    debug: bool = True
    
    # 腾讯云配置
    tencent_secret_id: str = "your_secret_id_here"
    tencent_secret_key: str = "your_secret_key_here"
    tencent_region: str = "ap-beijing"
    tencent_tiia_endpoint: str = "tiia.tencentcloudapi.com"
    
    # 腾讯云COS配置
    tencent_cos_bucket: str = "your_bucket_name"
    tencent_cos_region: str = "ap-beijing"
    
    # Coze 限流与并发配置（可通过 .env 覆盖）
    coze_upload_qps: float = 10.0
    coze_upload_burst: int = 15
    coze_upload_max_concurrency: int = 5  # 降低到5，避免连接器过载
    coze_general_qps: float = 200.0
    coze_general_burst: int = 300
    coze_general_max_concurrency: int = 5  # 降低到5，确保稳定运行

    # Coze HTTP 超时配置（秒）
    coze_upload_total_timeout: float = 60.0
    coze_upload_connect_timeout: float = 10.0
    coze_general_total_timeout: float = 30.0
    coze_general_connect_timeout: float = 5.0
    
    # 使用 Zeakai（OpenAI 兼容）接口的多密钥并发配置
    zeakai_api_keys: str = "6a375dc8-cddb-4276-9cae-e67247fee125，8cb4b8d8-dabc-422f-84fc-3c49f2765627"  # 逗号分隔，示例："keyA,keyB,keyC"
    zeakai_per_key_max_concurrency: int = 5  # 增加每个key的并发数到5
    zeakai_global_max_concurrency: int = 20  # 增加全局并发限制到20
    
    # 配置类，用于从环境变量加载配置
    class Config:
        env_file = ".env"

# 创建设置实例
settings = Settings()